home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / pi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  7.2 KB  |  260 lines

  1.  
  2.  
  3.    /**************************************************
  4.    *
  5.    *   file d:\cips\pi.c
  6.    *
  7.    *   Functions: This file contains
  8.    *       print_image
  9.    *       print_image_array
  10.    *       perform_printing
  11.    *       print_column_header
  12.    *
  13.    *   Purpose - These functions print an image out 
  14.    *       to the line printer.  The parameters in 
  15.    *       this function are defined differently 
  16.    *       than in most other CIPS functions.  
  17.    *       The parameters il, ie, ll, le are 
  18.    *       coordinates inside the 100x100 image array.
  19.    *       The parameters first_line and first_element
  20.    *       are coordinates for the entire image file.
  21.    *       So, if you want to start printing at row 10
  22.    *       and column 10 of the image file you would 
  23.    *       call:
  24.    *
  25.    *       read_tiff_image(name, the_image, 10, 10,
  26.    *                       110, 110);
  27.    *       print_image(the_image, name, 1, 1, 1, 
  28.    *                   100, 18, 10, 10);
  29.    *
  30.    *       In normal print mode you can only print 17
  31.    *       columns.
  32.    *       le - ie = 17.
  33.    *
  34.    *
  35.    *   External Calls:
  36.    *       none
  37.    *
  38.    *   Modifications:
  39.    *       6 January 1987 - created
  40.    *       14 August 1990 - modified to be part of the
  41.    *           C Image Processing System
  42.    *       14 June 1993 - removed calls to
  43.    *           my_fwrite my_fwriteln
  44.    *
  45.    **************************************************/
  46.  
  47. #include "cips.h"
  48. #define  FORMFEED  '\014'
  49.  
  50.    /*********************************************
  51.    *
  52.    *   printf_image(...
  53.    *
  54.    *********************************************/
  55.  
  56. print_image(the_image, name, channel, il, ie, ll, le,
  57.             first_line, first_element)
  58.    char  name[];
  59.    int   channel, il, ie, ll, le, 
  60.          first_line, first_element;
  61.    short the_image[ROWS][COLS];
  62. {
  63.    char printer_name[MAX_NAME_LENGTH];
  64.    FILE *printer;
  65.  
  66.    strcpy(printer_name, "prn");
  67.    if( (printer = fopen(printer_name, "w")) == NULL)
  68.       printf("\nPI> Could not open printer");
  69.    else{
  70.       printf("\nPI> The print file is opened");
  71.  
  72.            /*****************************************
  73.            *
  74.            *   If your printer has some form of
  75.            *   condensed printing, you can send those
  76.            *   commands via software using the fputc
  77.            *   function.  For example, if your printer
  78.            *   needs to sequence X Y Z to start
  79.            *   condensed printing, insert the following
  80.            *   three calls right here:
  81.            *   fputc('X', printer);
  82.            *   fputc('Y', printer);
  83.            *   fputc('Z', printer);
  84.            *
  85.            ******************************************/
  86.  
  87.       perform_printing(printer, the_image, name, 
  88.                        channel, il, ll, ie, le, 
  89.                        first_line, first_element);
  90.       fclose(printer);
  91.    }  /* ends else print  */
  92. }     /* ends print_image  */
  93.  
  94.  
  95.  
  96.  
  97.    /*********************************************
  98.    *
  99.    *   perform_printing(...
  100.    *
  101.    *********************************************/
  102.  
  103. perform_printing(printer, the_image, name, channel,
  104.                  il, ll, ie, le, first_line, 
  105.                  first_element)
  106.    char  name[];
  107.    FILE  *printer;
  108.    int   channel, il, ie, ll, le, 
  109.          first_line, first_element;
  110.    short the_image[ROWS][COLS];
  111. {
  112.    char output[3*COLS],
  113.         response[80],
  114.         string[3*COLS];
  115.    int  i,
  116.         j,
  117.         k,
  118.         line_counter;
  119.  
  120.  
  121.    printf("\nPI> Print header");
  122.    line_counter = 0;
  123.    pi_long_clear_buffer(string);
  124.    sprintf(string, "     This image is -- %s --\n", 
  125.            name);
  126.    fputs(string, printer);
  127.    ++line_counter;
  128.  
  129.    pi_long_clear_buffer(string);
  130.    sprintf(string, "     The parameters are:\n");
  131.    fputs(string, printer);
  132.    ++line_counter;
  133.  
  134.    pi_long_clear_buffer(string);
  135.    sprintf(string, 
  136.            "     channel=%d il=%d ll=%d ie=%d le=%d\n",
  137.            channel, first_line, first_line+ll-2,
  138.            first_element, first_element+le-2);
  139.    fputs(string, printer);
  140.    ++line_counter;
  141.  
  142.    pi_long_clear_buffer(string);
  143.    sprintf(string, " \n");
  144.    fputs(string, printer);
  145.    ++line_counter;
  146.  
  147.    print_column_header(&line_counter, first_element, 
  148.                        ie, le, output, string, 
  149.                        printer);
  150.  
  151.    for(i=il; i<ll; i++){
  152.  
  153.       pi_long_clear_buffer(string);
  154.  
  155.         /* now print the image  */
  156.       sprintf(string, "      ");
  157.       pi_long_clear_buffer(output);
  158.       sprintf(output, "%3d-", i+first_line-1);
  159.       strcat(string, output);
  160.       for(j=ie; j<le; j++){
  161.          pi_long_clear_buffer(output);
  162.          sprintf(output,"%4d",the_image[i][j]);
  163.          strcat(string, output);
  164.       }  /* ends loop over j columns */
  165.  
  166.       fputs(string, printer); fputc('\n', printer);
  167.       line_counter = line_counter + 1;
  168.       if(line_counter >= 53){
  169.          line_counter = 0;
  170.          putc(FORMFEED, printer);
  171.          print_column_header(&line_counter, 
  172.                              first_element, ie,
  173.                              le, output, string, 
  174.                              printer);
  175.       }  /* ends if line_counter >=65  */
  176.    }  /* ends loop over i rows */
  177.  
  178.    for(i=line_counter; i<66; i++){
  179.       pi_long_clear_buffer(string);
  180.       sprintf(string, " \n");
  181.       fputs(string, printer);
  182.    }
  183.  
  184. }     /* ends perform_printing  */
  185.  
  186.  
  187.  
  188.  
  189.    /*********************************************
  190.    *
  191.    *   print_column_header(...
  192.    *
  193.    *********************************************/
  194.  
  195. print_column_header(line_counter, first_element, 
  196.                     ie, le, output,
  197.                     string, printer)
  198.    char string[], output[];
  199.    FILE *printer;
  200.    int  first_element, ie, le, *line_counter;
  201. {
  202.    int k;
  203.  
  204.    pi_long_clear_buffer(string);
  205.    sprintf(string, "          ");
  206.  
  207.  
  208.    for(k=first_element;k<(first_element+(le-ie));k++){
  209.       pi_long_clear_buffer(output);
  210.       sprintf(output, "-%3d", k);
  211.       strcat(string, output);
  212.    }  /* ends loop over k  */
  213.    fputs(string, printer); fputc('\n', printer);
  214.    *line_counter = *line_counter + 1;
  215. }  /* ends print_column_header  */
  216.  
  217.  
  218.  
  219.  
  220.    /*************************************************
  221.    *
  222.    *   print_image_array(...
  223.    *
  224.    *   This function prints a 100x100 image array.
  225.    *
  226.    **************************************************/
  227.  
  228. print_image_array(the_image)
  229.    short the_image[ROWS][COLS];
  230. {
  231.    char response[80];
  232.    printf("\nPIA> Enter a comment line\n--");
  233.    gets(response);
  234.                                 /*     il  ie  ll    le    */
  235.    print_image(the_image, response, 0,  1,  1, 100,  17, 0, 0);
  236.    print_image(the_image, response, 0,  1, 18, 100,  35, 0, 0);
  237.    print_image(the_image, response, 0,  1, 36, 100,  53, 0, 0);
  238.    print_image(the_image, response, 0,  1, 54, 100,  71, 0, 0);
  239.    print_image(the_image, response, 0,  1, 72, 100,  89, 0, 0);
  240.    print_image(the_image, response, 0,  1, 90, 100, 100, 0, 0);
  241.  
  242. }  /* ends print_image_array  */
  243.  
  244.  
  245.  
  246.  
  247.    /*********************************************
  248.    *
  249.    *   pi_long_clear_string(...
  250.    *
  251.    *********************************************/
  252.  
  253. pi_long_clear_buffer(string)
  254.    char string[];
  255. {
  256.    int i;
  257.    for(i=0; i<300; i++)
  258.       string[i] = ' ';
  259. }
  260.